package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.base.BaseController;
import com.shop.entity.ProductAttributeValue;
import com.shop.result.ResultVO;
import com.shop.service.ProductAttributeValueService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/productAttributeValuer")
public class ProductAttributeValueController extends BaseController {
    private final ProductAttributeValueService productAttributeValueService;
    @PostMapping("/listProductAttributeValue")
    public ResultVO<Object> listProductAttributeValue(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        PageInfo<ProductAttributeValue> pageInfo = productAttributeValueService.listProductAttributeValue(page, limit);
        return success(pageInfo);
    }

    @PostMapping("/listWithProductAttributeValue")
    public ResultVO<Object> listWithProductAttributeValue(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageInfo<ProductAttributeValue> pageInfo = productAttributeValueService.listWithProductAttributeValue(pageNum, pageSize);
        return success(pageInfo);
    }
    @PostMapping("/getProductAttributeValueById")
    public ResultVO<Object> getProductAttributeValueById(@RequestParam("productAttributeValueId") Integer id) {
        ProductAttributeValue productAttributeValue = productAttributeValueService.getProductAttributeValueById(id);
        return success(productAttributeValue);
    }
    @PostMapping("/addProductAttributeValue")
    public ResultVO<Object> addProductAttributeValue(@RequestBody ProductAttributeValue productAttributeValue) {
        productAttributeValueService.addProductAttributeValue(productAttributeValue);
        return success();
    }
    @PostMapping("/deleteProductAttributeValue")
    public ResultVO<Object> deleteProductAttributeValue(@RequestParam("productAttributeValueId") Integer id) {
        productAttributeValueService.deleteProductAttributeValue(id);
        return success();
    }
    @PostMapping("/updateProductAttributeValue")
    public ResultVO<Object> updateProductAttributeValue(@RequestParam("productAttributeValueId") Integer id, @RequestParam("attributeId") Integer attributeId, @RequestParam("value") String value) {
        productAttributeValueService.updateProductAttributeValue(id, attributeId, value);
        return success();
    }
    @GetMapping("/getTotal")
    public ResultVO<Object> getTotal() {
        int total = productAttributeValueService.getTotal();
        return success(total);
    }
}
